/**
 * APIMainGoods
 * Created by yanjd on 2017/9/22.
 */
import {type} from '../type'
let api = {}

/**
 *  获取快销号列表
 * @param state
 * @param commit
 * @param params {...}
 * @returns {Promise}
 */
api.getFastsList = function ({state, commit, rootState}, params) {
  return new Promise((resolve, reject) => {
    rootState.axios.get(rootState.CONSTANTS.APIMainGoods + 'mainFastSalesAccount/getGameStartAccountConfig', {params}).then(({data}) => {
      if(data.data){
	      data.data = JSON.parse(data.data)
      }
      resolve(data.data || [])
    }, () => {
      //console.log('快销号列表请求错误 (╯‵□′)╯︵┻━┻')
      resolve([])
    })
  })
}

/**
 *  获取快销号信息
 * @param state
 * @param commit
 * @param params {...}
 * @returns {Promise}
 */
api.getFastsInfo = function ({state, commit, rootState}, params) {
  return rootState.axios.post(rootState.CONSTANTS.APIMGCoin + 'goodsSearch/getBizOfferGameStartAccount', params)
}

/**
 *  创建快销号单子
 * @param state
 * @param commit
 * @param params {...}
 * @returns {Promise}
 */
api.createFasts = function ({state, commit, rootState}, params) {

  return new Promise((resolve, reject) => {
    rootState.axios.post(rootState.CONSTANTS.APIMainGoods + 'mainFastSalesAccount/createOrder', params).then(({data}) => {
	    if(data.data){
		    data.data = JSON.parse(data.data)
	    }
      resolve(data || {})
    }, () => {
      //console.log('快销号列表请求错误 (╯‵□′)╯︵┻━┻')
      resolve([])
    })
  })
}

export default {
  ...api
}
